<?php
/**
 * 留言管理
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: MessageModel.class.php v1.0 2014-06-13 17:27:03 $
 */
namespace Home\Model;
class MessageModel extends CommonModel{
    private $field_infos;
    protected $_auto = array(
        array("userip", "get_client_ip", 1, "function"),
        array("subtime", "time", 1, "function"),
        array("status", 0),
    );
    
    /**
     * 获取自定义字段
     * @return type
     */
    public function getAddField($formname = '') {
        $this->field_infos= M("Field")->where(array("model_id" => 13))->select();
        //var_dump($as);die;
        return $this->getForm($formname);
    }
    
    /**
     * 获取表单
     * @param type $formname
     * @return string
     */
    private function getForm($formname = ''){
        $fields = $this->field_infos;
        $formstring = '';
        $formfields = '';
        if(is_array($fields)){
            foreach($fields as $field){
                $formstring .= GetFormItem($field, $formname, 'diy');
                $formfields .= $formfields == '' ? $field['name'].','.$field['type'] : ';'.$field['name'].','.$field['type'];
            }
        }
        $formstring .= "<input type=\"hidden\" name=\"yd_fields\" value=\"".$formfields."\" />\n";
        $formstring .= "<input type=\"hidden\" name=\"yd_fieldshash\" value=\"".md5($formfields . C("COOKIE_ENCODE"))."\" />";
        return $formstring;
    }
}
